<template>
	<!-- components/download/index.wxml -->
	<view class="download">
		<view class="download-text">更多提现方式，可以下载数码回收网报价单APP,下载方式如下:</view>
		<view class="download-title">方法一：应用商店搜索</view>
		<view class="download-img">
			<image
				src="https://smhs-1258084849.cos.ap-nanjing.myqcloud.com/smhswbulk/2023-10-13/01817202310131010472699.image/png">
			</image>
		</view>
		<view class="download-title">方法二：保存二维码或者复制链接</view>
		<view class="download-con">
			<view>
				<view class="download-con_code">
					<image @tap="preview" src="/static/image/download-qr.png"></image>
				</view>
				<view class="download-con_text">https://a.app.qq.com/o/simple.jsp?pkgname=com.smhsw.bjd&fromcase=40003
				</view>
			</view>
			<view class="download-flex">
				<view class="download-con_btn" style="margin-bottom: 30rpx"
					data-text="https://a.app.qq.com/o/simple.jsp?pkgname=com.smhsw.bjd&fromcase=40003" @tap="copytext">
					复制下载链接
				</view>
				<!-- #ifndef H5 -->
				<view class="download-con_btn"
					data-url="https://smhs-1258084849.cos.ap-nanjing.myqcloud.com/smhswbulk/2022-05-23/012d1202205231054146001.image/png"
					@tap="save">
					保存二维码
				</view>
				<!-- #endif -->
			</view>
		</view>
	</view>
</template>

<script>
	// components/download/index.js
	export default {
		data() {
			return {};
		},
		/**
		 * 组件的属性列表
		 */
		props: {},
		/**
		 * 组件的方法列表
		 */
		methods: {
			copytext: function(e) {
				console.log(e);
				const text = e.currentTarget.dataset.text;
				uni.setClipboardData({
					//准备复制的数据
					data: text,
					success: function(res) {
						uni.showToast({
							title: '复制成功'
						});
					}
				});
			},
			save: function(e) {
				const url = e.currentTarget.dataset.url;
				const that = this;
				// let fileName = new Date().valueOf();
				// let filePath = fileName + '.jpg'; //这边就是为了安卓做的兼容，因为安卓机有可能会将图片地址的后缀名读取为：unknow
				// uni.downloadFile({
				//     url: url,
				//     //需要保存的图片地址
				//     filePath: filePath,
				//     success: function (res) {
				// 保存图片到系统相册
				uni.saveImageToPhotosAlbum({
					filePath: url,
					success(data) {
						// let fileMgr = uni.getFileSystemManager();
						// fileMgr.unlink({
						//     filePath: filePath,
						//     success() {
						uni.showToast({
							title: '已保存至您的相册',
							icon: 'none',
							duration: 1500
						});
						//     }
						// });
					},
					fail(err) {
						if (
							err.errMsg === 'saveImageToPhotosAlbum:fail:auth denied' ||
							err.errMsg === 'saveImageToPhotosAlbum:fail auth deny' ||
							err.errMsg === 'saveImageToPhotosAlbum:fail authorize no response'
						) {
							uni.showModal({
								title: '提示',
								content: '需要您授权保存相册',
								showCancel: false,
								success: modalSuccess => {
									uni.openSetting({
										success(settingdata) {
											if (settingdata.authSetting[
													'scope.writePhotosAlbum']) {
												console.log('获取权限成功，给出再次点击图片保存到相册的提示。');
											} else {
												console.log('获取权限失败，给出不给权限就无法正常使用的提示');
											}
										}
									});
								}
							});
						}
					}
				});
				//     },
				//     fail: function (res) {}
				// });
			},

			preview() {
				uni.previewImage({
					current: 'https://smhs-1258084849.cos.ap-nanjing.myqcloud.com/smhswbulk/2022-05-23/012d1202205231054146001.image/png',
					urls: [
						'https://smhs-1258084849.cos.ap-nanjing.myqcloud.com/smhswbulk/2022-05-23/012d1202205231054146001.image/png']
				});
			}
		}
	};
</script>
<style>
	@import './index.css';
</style>